home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / gui / precog2_1.lha / Precognition2_1 / src / src.lha / Library / CheckBox.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-07-19  |  6.2 KB  |  265 lines

  1. #include <stdio.h>
  2. #include "CheckBox.h"
  3. #include "CheckBoxClass.h"
  4. #include "Precognition_utils.h"
  5. #include "minmax.h"
  6. #include "AmigaMem.h"
  7. #ifndef __GNUC__
  8. #include <clib/graphics_protos.h>
  9. #include <clib/intuition_protos.h>
  10. #include <clib/exec_protos.h>
  11. #endif
  12. #ifdef __GNUC__
  13. #include <proto/graphics.h>
  14. #include <proto/intuition.h>
  15. #include <proto/exec.h>
  16. #endif
  17. #ifdef __SASC
  18. #include <proto/graphics.h>
  19. #include <proto/intuition.h>
  20. #include <proto/exec.h>
  21. #endif
  22. /* Additions for prototypes -- EDB */
  23. #include "EmbossedGadgetClass.h"
  24. #include "BoolGadgetClass.h"
  25.  
  26.  
  27. typedef struct CheckInfo
  28.    {
  29.       Border CheckMark;
  30.       BOOL   Selected;
  31.    } CheckInfo;
  32.  
  33.  
  34.  
  35. WORD CheckBox_CheckMarkPoints[] = { 16,3, 9,10, 6,10, 6,6, 7,6, 7,10,
  36.          14,3, 15,3, 8,10, 8,5, 4,5 };
  37.  
  38.  
  39.  
  40.  
  41. void CheckBox_CleanUp( CheckBox *self )
  42. {
  43.    Afree( self->g.SpecialInfo );
  44.    self->g.SpecialInfo = NULL;
  45. }
  46.  
  47.  
  48. tPoint CheckBox_FixedSize = { 22, 14 };
  49.  
  50. tPoint CheckBox_AskSize( CheckBox *self,
  51.                          PIXELS    Width,
  52.                          PIXELS    Height )
  53. {
  54.    return CheckBox_FixedSize;
  55. }
  56.  
  57.  
  58.  
  59. USHORT CheckBox_ClaimEvent( CheckBox   *self,
  60.                             IntuiMessage  *event )
  61. {
  62.    USHORT response = 0;
  63.  
  64.    switch( event->Class )
  65.    {
  66.       case REFRESHWINDOW:
  67.          response = RESPONDED;
  68.          break;
  69.  
  70.       case GADGETUP:
  71.          if( event->IAddress == (void *)&self->g )
  72.          {
  73.             response = RESPONDED | CONSUMED_EVENT | CHANGED_STATE;
  74.          }
  75.          break;
  76.    }
  77.  
  78.    return response;
  79. }
  80.  
  81.  
  82. LONG CheckBox_Value( CheckBox *self )
  83. {
  84.    CheckInfo *info;
  85.  
  86.    info = (CheckInfo *)self->g.SpecialInfo;
  87.  
  88.    return (LONG)info->Selected;
  89. }
  90.  
  91.  
  92. LONG CheckBox_SetValue( CheckBox *self,
  93.                             LONG      selection )
  94. {
  95.    CheckInfo *info;
  96.  
  97.    info = (CheckInfo *)self->g.SpecialInfo;
  98.  
  99.    info->Selected = selection;
  100.  
  101.    if( selection )
  102.    {
  103.       Forbid();
  104.       self->BoxBorder->BottomRight.NextBorder = &info->CheckMark;
  105.       Permit();
  106.    }
  107.    else
  108.    {
  109.       Forbid();
  110.       self->BoxBorder->BottomRight.NextBorder = NULL;
  111.       Permit();
  112.    }
  113.  
  114.    return (LONG)info->Selected;
  115. }
  116.  
  117. void CheckBox_Render( CheckBox *self,
  118.                       RastPort *RPort )
  119. {
  120.    PIXELS xmin, xmax, ymin, ymax;
  121.  
  122.    xmin = self->Location.x + 2;
  123.    ymin = self->Location.y + 2;
  124.    xmax = xmin + self->Size.x - 4;
  125.    ymax = ymin + self->Size.y - 4;
  126.    SetAPen( RPort, self->Pens.BackPen );
  127.    SetDrMd( RPort, JAM1 );
  128.    RectFill( RPort, xmin, ymin, xmax, ymax );
  129.  
  130.    EmbossedGadget_Render( self, RPort );
  131. }
  132.  
  133.  
  134. USHORT CheckBox_Respond( CheckBox     *self,
  135.                          IntuiMessage *event )
  136. {
  137.    CheckInfo *info;
  138.    USHORT     response = 0;
  139.    Window    *window;
  140.    USHORT     selection;
  141.  
  142.    switch( event->Class )
  143.    {
  144.       case REFRESHWINDOW:
  145.          response = RESPONDED;
  146.          break;
  147.  
  148.       case GADGETUP:
  149.          if( event->IAddress == (void *)&self->g )
  150.          {
  151.             window = event->IDCMPWindow;
  152.  
  153.             info      = (CheckInfo *)self->g.SpecialInfo;
  154.             selection = ! info->Selected;
  155.  
  156.             SetValue( (Valuator *)self, selection );
  157.             Render( (GraphicObject *)self, window->RPort );
  158.  
  159.             response = RESPONDED | CONSUMED_EVENT | CHANGED_STATE;
  160.          }
  161.          break;
  162.  
  163.    }
  164.  
  165.    return response;
  166.  
  167.  
  168. }
  169.  
  170.  
  171. BOOL CheckBox_elaborated = FALSE;
  172.  
  173. struct ValuatorClass CheckBox_Class;
  174.  
  175. void CheckBoxClass_Init( struct ValuatorClass *class )
  176. {
  177.    BoolGadgetClass_Init( class );
  178.    class->isa         = BoolGadgetClass();
  179.    class->ClassName   = "CheckBox";
  180.  
  181. /* -------- Commented-out methods are inherited ----------------*/
  182.    class->CleanUp     = (void(*)(PObject *))CheckBox_CleanUp;
  183. /*   class->Location    = CheckBox_Location;*/
  184. /*   class->SetLocation = CheckBox_SetLocation;*/
  185. /*   class->Size        = CheckBox_Size;*/
  186. /*   class->SetSize     = CheckBox_SetSize;*/
  187.    class->AskSize     = (Point(*)(GraphicObject *, PIXELS, PIXELS))CheckBox_AskSize;
  188.    class->SizeFlags  = GraphicObject_SizeFlagsNone;
  189.    class->Render      = (void(*)(GraphicObject *, RastPort *))CheckBox_Render;
  190. /*   class->FirstGadget = CheckBox_FirstGadget;*/
  191. /*   class->nGadgets    = CheckBox_nGadgets;*/
  192. /*   class->IDCMPFlags  = CheckBox_IDCMPFlags;*/
  193.    class->ClaimEvent  = (USHORT(*)(Interactor *, IntuiMessage *))CheckBox_ClaimEvent;
  194.    class->Respond     = (USHORT(*)(Interactor *, IntuiMessage *))CheckBox_Respond;
  195. /*   class->EnableIactor      = CheckBox_EnableIactor;*/
  196. /*   class->isEnabled   = CheckBox_isEnabled;*/
  197. /*   class->Activate    = NULL;*/
  198. /*   class->isActive    = NULL;*/
  199.    class->Value     = (LONG(*)(Valuator *))CheckBox_Value;
  200.    class->SetValue  = (LONG(*)(Valuator *, LONG))CheckBox_SetValue;
  201.  
  202.  
  203. }
  204.  
  205.  
  206. struct ValuatorClass *CheckBoxClass( void )
  207. {
  208.    if( ! CheckBox_elaborated )
  209.    {
  210.       CheckBoxClass_Init( &CheckBox_Class );
  211.       CheckBox_elaborated = TRUE;
  212.    }
  213.  
  214.    return &CheckBox_Class;
  215. }
  216.  
  217.  
  218. void CheckBox_Init( CheckBox *self,
  219.                     PIXELS      LeftEdge,
  220.                     PIXELS      TopEdge,
  221.                     pcg_3DPens  Pens,
  222.                     char       *Label,
  223.                     BOOL        Selected )
  224. {
  225.    tPoint     size;
  226.    CheckInfo *info;
  227.    AlignInfo  *ainfo;
  228.  
  229. /*DUMPWAIT("CheckBox_Init\n");*/
  230.  
  231.    Interactor_Init( (Interactor *)self );
  232.  
  233.    self->isa  = CheckBoxClass();
  234.    size       = AskSize( (GraphicObject *)self, 0, 0 );
  235.  
  236.  
  237.    BoolGadget_Init( self, LeftEdge, TopEdge, size.x, size.y,
  238.                         Pens, Label );
  239.  
  240.    self->isa     = CheckBoxClass();
  241. /* remove GADGHCOMP -- EDB */
  242.    self->g.Flags = /* GFLG_GADGHNONE; */  GADGHCOMP;
  243.  
  244.    ainfo = TextAlignment( (GraphicObject *)self );
  245.    SetTextAlignment( (GraphicObject *)self, tx_RIGHT | tx_YCENTER | tx_OUTSIDE,
  246.       ainfo->Xpad, ainfo->Ypad );
  247.  
  248.    info = (CheckInfo *)Acalloc( 1, sizeof( CheckInfo ) );
  249.    info->Selected         = Selected;
  250.  
  251.    info->CheckMark.LeftEdge   = 0;
  252.    info->CheckMark.TopEdge    = 0;
  253.    info->CheckMark.FrontPen   = Pens.FrontPen;
  254.    info->CheckMark.BackPen    = Pens.BackPen;
  255.    info->CheckMark.DrawMode   = JAM1;
  256.    info->CheckMark.Count      = 11;
  257.    info->CheckMark.XY         = CheckBox_CheckMarkPoints;
  258.    info->CheckMark.NextBorder = NULL;
  259.    self->g.SpecialInfo        = (APTR)info;
  260.  
  261.    SetValue( (Valuator *)self, (USHORT)Selected );
  262.  
  263. /*DUMPWAIT("end Checkbox_Init\n");*/
  264. }
  265.